package com.example.wx.demo.wx;


import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import weixin.popular.api.TicketAPI;
import weixin.popular.api.TokenAPI;

/**
 * @author zhangd
 */
@Slf4j
@Service
public class AccountTokenServiceImpl implements AccountTokenService {

    /**
     * 微信appid
     */
    @Value("${wx.appid}")
    private String appId;

    /**
     * 微信秘钥
     */
    @Value("${wx.appsecret}")
    private String appSecret;


    @Override
    public String getWxToken() {
        try {
            return TokenAPI.token(appId, appSecret).getAccess_token();
        } catch (Exception e) {
            throw new RuntimeException("GET_ACCESS_TOKEN_FAIL");
        }
    }

    @Override
    public String getJsApiTicket(String accessToken) {
        return TicketAPI.ticketGetticket(accessToken).getTicket();
    }

}
